package org.mspring.mlog.api.regioncache.key;

import org.aspectj.lang.JoinPoint;
import org.mspring.mlog.api.regioncache.RegionCache;
import org.mspring.mlog.api.regioncache.key.generate.GenerateKey;
import org.mspring.platform.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author Gao Youbo
 * @since 2014年1月1日
 */
public class Generator {
    private static final Logger log = LoggerFactory.getLogger(Generator.class);

    public static String generate(JoinPoint point, RegionCache regionCache) {
        if (StringUtils.isNotBlank(regionCache.cacheKey())) {
            return regionCache.cacheKey();
        }
        try {
            GenerateKey generateKey = regionCache.generateKey().newInstance();
            return generateKey.generate(point);
        } catch (InstantiationException | IllegalAccessException e) {
            // TODO Auto-generated catch block
            log.error("generate key failure!", e);
        }
        return null;
    }
}
